<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
        html{height:100%}
        body{height:100%;margin:0px;padding:0px}
        #container{height:70%}
    </style>
    <!--核心插件-->
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=32mOZToZ1kGRUDb1oRy6IjT32eqxH3pa"></script>
    <!--绘制图案-->
    <script type="text/javascript" src="http://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.js"></script>
    <link rel="stylesheet" href="http://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.css" />
</head>
<body>
<div id="container"></div>
</body>
</html>


<script>
    var map = new BMap.Map("container");
    var point = new BMap.Point(116.404, 39.916);
    map.centerAndZoom(point, 15);
    var marker = new BMap.Marker(point);        // 创建标注
    map.addOverlay(marker);                     // 将标注添加到地图中

    marker.addEventListener("click", function(){
        alert("您点击了标注");
    });
    //拖拽标注
    marker.enableDragging();
    marker.addEventListener("dragend", function(e){
        alert("当前位置：" + e.point.lng + ", " + e.point.lat);
    })


</script>


<script>
    //指定经纬度获取地址
    // 创建地理编码实例
    var myGeo = new BMap.Geocoder();
    // 根据坐标得到地址描述
    myGeo.getLocation(new BMap.Point(116.364, 39.993), function(result){
        if (result){
            alert(result.address);
        }
    });
</script>

<script>
    //点击地图获取地址
    var geoc = new BMap.Geocoder();
    map.addEventListener("click", function(e){
        var pt = e.point;
        geoc.getLocation(pt, function(rs){
            var addComp = rs.addressComponents;
            alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
        });
    });
</script>


